﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
// network stuff
using System.Net;
using System.Net.Sockets;
using System.Net.NetworkInformation;

namespace NetSnoop
{
    public partial class FMain : Form
    {
        public FMain()
        {
            InitializeComponent();
        }

        private void FMain_Load(object sender, EventArgs e)
        {

            // define net helper
            CNetHelper NetHelper = new CNetHelper();

            // retrieve data
            TcpConnectionInformation[] ActiveConnections = NetHelper.GetTCPConnection();
            IPEndPoint[] ActiveListener = NetHelper.GetTCPListener();

            // fill grid view

            // tcp connections
            foreach (TcpConnectionInformation tmpItem in ActiveConnections)
            {

                ListViewItem tmpListItem = new ListViewItem();

                try
                {

                    tmpListItem = new ListViewItem();

                    tmpListItem.SubItems.Add("TCP");
                    tmpListItem.SubItems.Add(tmpItem.LocalEndPoint.Address.ToString());
                    tmpListItem.SubItems.Add(tmpItem.LocalEndPoint.Port.ToString());
                    tmpListItem.SubItems.Add(tmpItem.RemoteEndPoint.Address.ToString());
                    tmpListItem.SubItems.Add(tmpItem.RemoteEndPoint.Port.ToString());
                    tmpListItem.SubItems.Add(tmpItem.State.ToString());

                    this.listView1.Items.Add(tmpListItem);

                }
                catch (Exception ex)
                {
                    throw (ex);
                }

                
            }


            
        }

    }
}
